#include "LSE_RSE_Convert.h"

void ConvertToRse(vector<int>* T,Lse& lse,Rse& rse)
{
	int** temp;
	temp = new int*[lse.GetT()->getSize()+1];
	for(int i=0; i<lse.GetT()->getSize()+1 ; i++)
	{
		temp[i] = new int[T[i].size()];
		for(unsigned int j=0; j<T[i].size() ; j++)
		{
			temp[i][j]=T[i][j];
		}
		//clear all values of T and put zeros instead
		T[i].clear();
		for(int j=0; j<=rse.get_JofI(i); j++)
		{
			T[i].push_back(0);
		}
	}
	//transform T to LSE from RSE
	for(int i=0; i<rse.GetT()->getSize()+1 ; i++)
	{
		for(int j=0; j<=lse.get_JofI(i); j++)
		{
			int i1,j1;
			i1 = lse.GetForest(i,j)->getData()->getLTRP();
			j1 = i+j-i1;
			T[i1][j1] = temp[i][j];
		}
	}

	for(int i=0; i<lse.GetT()->getSize()+1 ; i++)
		delete[] temp[i];
	delete[] temp;
}


void ConvertToLse(vector<int>* T,Lse& lse,Rse& rse)
{
	int** temp;//temporery place to hold the values of T
	temp = new int*[rse.GetT()->getSize()+1];
	for(int i=0; i<rse.GetT()->getSize()+1 ; i++)
	{
		temp[i] = new int[T[i].size()];
		for(unsigned int j=0; j < T[i].size() ; j++)
		{
			temp[i][j]=T[i][j];
		}
		//clear all values of T and put zeros instead
		T[i].clear();
		for(int j=0; j<=lse.get_JofI(i); j++)
		{
			T[i].push_back(0);
		}
	}
	//transform T to RSE from LSE
	for(int i=0; i<lse.GetT()->getSize()+1 ; i++)
	{
		for(int j=0; j<=rse.get_JofI(i) ; j++)
		{
			int i1,j1;
			i1 = rse.GetForest(i,j)->getData()->getRTLP();
			j1 = i+j-i1;
			T[i1][j1] = temp[i][j];
		}
	}

	for(int i=0; i<rse.GetT()->getSize()+1 ; i++)
		delete[] temp[i];
	delete[] temp;
}

